home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / dbus / exceptions.py < prev    next >
Text File  |  2009-05-06  |  4KB  |  107 lines

  1. """D-Bus exceptions."""
  2.  
  3. # Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
  4. #
  5. # Permission is hereby granted, free of charge, to any person
  6. # obtaining a copy of this software and associated documentation
  7. # files (the "Software"), to deal in the Software without
  8. # restriction, including without limitation the rights to use, copy,
  9. # modify, merge, publish, distribute, sublicense, and/or sell copies
  10. # of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be
  14. # included in all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. # DEALINGS IN THE SOFTWARE.
  24.  
  25. __all__ = ('DBusException', 'MissingErrorHandlerException',
  26.            'MissingReplyHandlerException', 'ValidationException',
  27.            'IntrospectionParserException', 'UnknownMethodException',
  28.            'NameExistsException')
  29.  
  30. class DBusException(Exception):
  31.  
  32.     include_traceback = False
  33.     """If True, tracebacks will be included in the exception message sent to
  34.     D-Bus clients.
  35.  
  36.     Exceptions that are not DBusException subclasses always behave
  37.     as though this is True. Set this to True on DBusException subclasses
  38.     that represent a programming error, and leave it False on subclasses that
  39.     represent an expected failure condition (e.g. a network server not
  40.     responding)."""
  41.  
  42.     def __init__(self, *args, **kwargs):
  43.         name = kwargs.pop('name', None)
  44.         if name is not None or getattr(self, '_dbus_error_name', None) is None:
  45.             self._dbus_error_name = name
  46.         if kwargs:
  47.             raise TypeError('DBusException does not take keyword arguments: %s'
  48.                             % ', '.join(kwargs.keys()))
  49.         Exception.__init__(self, *args)
  50.  
  51.     def __str__(self):
  52.         s = Exception.__str__(self)
  53.         if self._dbus_error_name is not None:
  54.             return '%s: %s' % (self._dbus_error_name, s)
  55.         else:
  56.             return s
  57.  
  58.     def get_dbus_message(self):
  59.         s = Exception.__str__(self)
  60.         return s.decode('utf-8', 'replace')
  61.  
  62.     def get_dbus_name(self):
  63.         return self._dbus_error_name
  64.  
  65. class MissingErrorHandlerException(DBusException):
  66.  
  67.     include_traceback = True
  68.  
  69.     def __init__(self):
  70.         DBusException.__init__(self, "error_handler not defined: if you define a reply_handler you must also define an error_handler")
  71.  
  72. class MissingReplyHandlerException(DBusException):
  73.  
  74.     include_traceback = True
  75.  
  76.     def __init__(self):
  77.         DBusException.__init__(self, "reply_handler not defined: if you define an error_handler you must also define a reply_handler")
  78.  
  79. class ValidationException(DBusException):
  80.  
  81.     include_traceback = True
  82.  
  83.     def __init__(self, msg=''):
  84.         DBusException.__init__(self, "Error validating string: %s"%msg)
  85.  
  86. class IntrospectionParserException(DBusException):
  87.  
  88.     include_traceback = True
  89.  
  90.     def __init__(self, msg=''):
  91.         DBusException.__init__(self, "Error parsing introspect data: %s"%msg)
  92.  
  93. class UnknownMethodException(DBusException):
  94.  
  95.     include_traceback = True
  96.     _dbus_error_name = 'org.freedesktop.DBus.Error.UnknownMethod'
  97.  
  98.     def __init__(self, method):
  99.         DBusException.__init__(self, "Unknown method: %s"%method)
  100.  
  101. class NameExistsException(DBusException):
  102.  
  103.     include_traceback = True
  104.  
  105.     def __init__(self, name):
  106.         DBusException.__init__(self, "Bus name already exists: %s"%name)
  107.